"use strict";
cc._RF.push(module, '9e98eCtw8tCR6UAJkWYfNjd', 'AudioPlayer');
// eazax-ccc/core/AudioPlayer.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * 音频播放类
 */
var AudioPlayer = /** @class */ (function () {
    function AudioPlayer() {
    }
    Object.defineProperty(AudioPlayer, "masterVolume", {
        /**
         * 主音量
         */
        get: function () { return this._masterVolume; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(AudioPlayer, "musicVolume", {
        /**
         * 音乐音量
         */
        get: function () { return this._musicVolume; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(AudioPlayer, "effectVolume", {
        /**
         * 特效音量
         */
        get: function () { return this._effectVolume; },
        enumerable: false,
        configurable: true
    });
    /**
     * 设置主音量
     * @param value 音量值（0.0 ~ 1.0）
     */
    AudioPlayer.setMasterVolume = function (value) {
        if (value < 0.0)
            value = 0.0;
        else if (value > 1.0)
            value = 1.0;
        this._masterVolume = value;
        this.setMusicVolume(this._musicVolume);
        this.setEffectVolume(this._effectVolume);
    };
    /**
     * 设置音量（音乐与特效）
     * @param value 音量值（0.0 ~ 1.0）
     */
    AudioPlayer.setVolume = function (value) {
        this.setMusicVolume(value);
        this.setEffectVolume(value);
    };
    /**
     * 设置音乐音量
     * @param value 音量值（0.0 ~ 1.0）
     */
    AudioPlayer.setMusicVolume = function (value) {
        if (value < 0.0)
            value = 0.0;
        else if (value > 1.0)
            value = 1.0;
        this._musicVolume = value;
        var realVolume = this._masterVolume * value;
        this._music.forEach(function (id, clip) { return cc.audioEngine.setVolume(id, realVolume); });
    };
    /**
     * 设置特效音量
     * @param value 音量值（0.0 ~ 1.0）
     */
    AudioPlayer.setEffectVolume = function (value) {
        if (value < 0.0)
            value = 0.0;
        else if (value > 1.0)
            value = 1.0;
        this._effectVolume = value;
        var realVolume = this._masterVolume * value;
        this._effect.forEach(function (clip, id) { return cc.audioEngine.setVolume(id, realVolume); });
    };
    /**
     * 播放音乐
     * @param clip 音频
     */
    AudioPlayer.playMusic = function (clip) {
        if (this._music.has(clip))
            this.stopMusic(clip);
        var id = cc.audioEngine.play(clip, true, this._masterVolume * this._musicVolume);
        this._music.set(clip, id);
    };
    /**
     * 停止音乐
     * @param clip 音频
     */
    AudioPlayer.stopMusic = function (clip) {
        if (!this._music.has(clip))
            return;
        cc.audioEngine.stop(this._music.get(clip));
        this._music.delete(clip);
    };
    /**
     * 停止所有音乐
     */
    AudioPlayer.stopAllMusic = function () {
        var _this = this;
        this._music.forEach(function (id, clip) { return _this.stopMusic(clip); });
    };
    /**
     * 暂停音乐
     * @param clip 音频
     */
    AudioPlayer.pauseMusic = function (clip) {
        if (!this._music.has(clip))
            return;
        cc.audioEngine.pause(this._music.get(clip));
    };
    /**
     * 暂停所有音乐
     */
    AudioPlayer.pauseAllMusic = function () {
        var _this = this;
        this._music.forEach(function (id, clip) { return _this.pauseMusic(clip); });
    };
    /**
     * 恢复音乐
     * @param clip 音频
     */
    AudioPlayer.resumeMusic = function (clip) {
        if (!this._music.has(clip))
            return;
        cc.audioEngine.resume(this._music.get(clip));
    };
    /**
     * 恢复所有音乐
     */
    AudioPlayer.resumeAllMusic = function () {
        var _this = this;
        this._music.forEach(function (id, clip) { return _this.resumeMusic(clip); });
    };
    /**
     * 播放特效音频
     * @param clip 音频
     * @param loop 循环
     */
    AudioPlayer.playEffect = function (clip, loop) {
        var _this = this;
        var id = cc.audioEngine.play(clip, loop, this._masterVolume * this._effectVolume);
        this._effect.set(id, clip);
        if (!loop)
            cc.audioEngine.setFinishCallback(id, function () { return _this._effect.delete(id); });
    };
    /**
     * 停止特效音频
     * @param clip 音频
     */
    AudioPlayer.stopEffect = function (clip) {
        var _this = this;
        this._effect.forEach(function (_clip, id) {
            if (_clip === clip) {
                cc.audioEngine.stop(id);
                _this._effect.delete(id);
            }
        });
    };
    /**
     * 停止所有特效音频
     */
    AudioPlayer.stopAllEffect = function () {
        var _this = this;
        this._effect.forEach(function (clip, id) {
            cc.audioEngine.stop(id);
            _this._effect.delete(id);
        });
    };
    /**
     * 暂停特效音频
     * @param clip 音频
     */
    AudioPlayer.pauseEffect = function (clip) {
        this._effect.forEach(function (_clip, id) { return _clip === clip && cc.audioEngine.pause(id); });
    };
    /**
     * 暂停所有特效音频
     */
    AudioPlayer.pauseAllEffect = function () {
        this._effect.forEach(function (clip, id) { return cc.audioEngine.pause(id); });
    };
    /**
     * 恢复特效音频
     * @param clip 音频
     */
    AudioPlayer.resumeEffect = function (clip) {
        this._effect.forEach(function (_clip, id) { return _clip === clip && cc.audioEngine.resume(id); });
    };
    /**
     * 恢复所有特效音频
     */
    AudioPlayer.resumeAllEffect = function () {
        this._effect.forEach(function (clip, id) { return cc.audioEngine.resume(id); });
    };
    /**
     * 停止所有音频
     */
    AudioPlayer.stopAll = function () {
        this.stopAllMusic();
        this.stopAllEffect();
    };
    /**
     * 暂停所有音频
     */
    AudioPlayer.pauseAll = function () {
        this.pauseAllMusic();
        this.pauseAllEffect();
    };
    /**
     * 恢复所有音频
     */
    AudioPlayer.resumeAll = function () {
        this.resumeAllMusic();
        this.resumeAllEffect();
    };
    /**
     * 静音
     */
    AudioPlayer.mute = function () {
        this.setMasterVolume(0.0);
    };
    AudioPlayer._music = new Map();
    AudioPlayer._effect = new Map();
    AudioPlayer._masterVolume = 1.0;
    AudioPlayer._musicVolume = 1.0;
    AudioPlayer._effectVolume = 1.0;
    return AudioPlayer;
}());
exports.default = AudioPlayer;

cc._RF.pop();